package com.jinyang.baserouter.pathreplace

import android.content.Context
import android.net.Uri
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.facade.service.PathReplaceService
import com.jinyang.baserouter.PATH_ACTIVITY_LOGIN
import com.jinyang.baserouter.PATH_ACTIVITY_MAIN
import com.jinyang.baserouter.PATH_ACTIVITY_REGISTER
import com.jinyang.baserouter.log


/**
 * @Author:         LiuJinYang
 * @CreateDate:     2021/12/9
 * @Description:重写跳转URL
 */
// 实现PathReplaceService接口，并加上一个Path内容任意的注解即可
@Route(path = "/pathReplace/test") // 必须标明注解
class TestPathReplaceServiceImpl : PathReplaceService {
    override fun init(context: Context?) {
        log("TestPathReplaceServiceImpl.init")
    }

    /**
     * For normal path.
     *
     * @param path raw path
     */
    override fun forString(path: String): String {
        log("TestPathReplaceServiceImpl.replacePath")
        // 按照一定的规则处理之后返回处理后的结果
        return if (path == PATH_ACTIVITY_MAIN) PATH_ACTIVITY_LOGIN else path
    }

    /**
     * For uri type.
     *
     * @param uri raw uri
     */
    override fun forUri(uri: Uri?): Uri? {
        log("TestPathReplaceServiceImpl.replaceUri")
        return uri // 按照一定的规则处理之后返回处理后的结果
    }
}